package com.sc.oa.service;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.xwork.StringUtils;
import com.sc.oa.base.BaseDaoImpl;
import com.sc.oa.entity.UserAccout;
import com.sc.oa.service.impl.IUserAccoutService;

@SuppressWarnings("unchecked")
public class UserAccoutSevice extends BaseDaoImpl<UserAccout> implements IUserAccoutService{


	@Override
	public UserAccout login(UserAccout user) {
		String whereHql = "";
		List paramsList = new ArrayList();
		if(StringUtils.isNotBlank(user.getAccount())){
			whereHql = whereHql+" and o.account=?";
			paramsList.add(user.getAccount());
		}
		if(StringUtils.isNotBlank(user.getPassword())){
			whereHql = whereHql+" and o.password=?";
			//	paramsList.add(DigestUtils.md5Hex(user.getPassword()));
			paramsList.add(user.getPassword());
		}
		if(StringUtils.isNotBlank(user.getEmail())){
			whereHql = whereHql+" and o.email=?";
			paramsList.add(user.getEmail());
		}
		Object[] values = paramsList.toArray();
		List<UserAccout> list = findObjectByConditionWithNoPage(whereHql, values);
		if(list.size()>0){
			return list.get(0);
		}
		return null;
	}

}
